
#ifndef RTTHREADREACTOR_H
#define RTTHREADREACTOR_H

#include "RtThreadInterface.h"
#include "RtDnsManager.h"

class IRtReactor;

class CRtThreadReactor : public CRtThread  
{
public:
	CRtThreadReactor();
	virtual ~CRtThreadReactor();

	RtResult Init(IRtReactor *aReactor);

	// interface CRtThread
	virtual RtResult Create
		(CRtThreadManager::TType aType, 
		CRtThreadManager::TFlag aFlag = CRtThreadManager::TF_JOINABLE);
	
	virtual RtResult Stop(CRtTimeValue* aTimeout = NULL);

	virtual void OnThreadInit();
	virtual void OnThreadRun();

	virtual IRtReactor* GetReactor();
	virtual IRtEventQueue* GetEventQueue();
	virtual IRtTimerQueue* GetTimerQueue();

#ifdef RT_WIN32_ENABLE_AsyncGetHostByName
	void RegisterDnsManager(CRtDnsManager* inDnsManager) { m_dnsManager = inDnsManager; }
#endif

private:
	IRtReactor *m_pReactor;
#ifdef RT_WIN32_ENABLE_AsyncGetHostByName
	CRtDnsManager* m_dnsManager;
#endif
};

/// used for netwok thread is the same as main thread.
class CRtThreadDummy : public CRtThread  
{
public:
	CRtThreadDummy();
	virtual ~CRtThreadDummy();

	RtResult Init(CRtThread *aThread, CRtThreadManager::TType aType);

	// interface CRtThread
	virtual RtResult Create(
		CRtThreadManager::TType aType, 
		CRtThreadManager::TFlag aFlag = CRtThreadManager::TF_JOINABLE);

	virtual RtResult Stop(CRtTimeValue* aTimeout = NULL);

	virtual void OnThreadRun();

	virtual IRtReactor* GetReactor();
	virtual IRtEventQueue* GetEventQueue();
	virtual IRtTimerQueue* GetTimerQueue();

private:
	CRtThread *m_pActualThread;
};

#endif // !RTTHREADREACTOR_H
